#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
#define LL long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
int tmpInt;LL tmpLL;string tmpStr;char tmpChar;
vector<int>tmpIntVector;
struct node{
  
};

int main(){
  int t;scanf("%d",&t);
  XH(i,0,t){
   int n;scanf("%d",&n); 
   tmpIntVector.resize(n);
   XH(i,0,n){
    scanf("%d",&tmpIntVector[i]);    
   }
   sort(tmpIntVector.begin(),tmpIntVector.end());
   int cnt = 1;
   while(cnt < n && tmpIntVector[cnt]==tmpIntVector[cnt-1]){
     ++cnt;
   }
   printf("%d\n", n - cnt);
  }

  return 0;
}
